package com.yyzx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yyzx.pojo.Nurselevel;
import com.yyzx.pojo.vo.PageResult;
import com.yyzx.pojo.vo.Result;
import com.yyzx.service.NurselevelService;
import com.yyzx.mapper.NurselevelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author qubo
* @description 针对表【nurselevel(存储护理等级的定义（用于区分客户护理服务的等级）)】的数据库操作Service实现
* @createDate 2025-10-13 14:52:38
*/
@Service
public class NurselevelServiceImpl extends ServiceImpl<NurselevelMapper, Nurselevel>
    implements NurselevelService{
    @Autowired
    private NurselevelMapper nurselevelMapper;

    /**
     * 分页+条件查询护理级别
     */
    @Override
    public Result<PageResult<List<Nurselevel>>> getList(Integer currentPage, Integer pageSize, String levelName, Integer levelStatus) {
        // 设置分页参数
        Page<Nurselevel> page = new Page<>(currentPage, pageSize);
        // 设置条件查询
        QueryWrapper<Nurselevel> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(levelName), "level_name", levelName)
                .or()
                .like(levelStatus!=null,"level_status", levelStatus);
        // 查询
        nurselevelMapper.selectPage(page,wrapper);
        // 构造分页条件查询的结果集
        PageResult<List<Nurselevel>> pageResult = new PageResult<>();
        if( page.getRecords().size() == 0 ){
            pageResult.setTotal(0L);
            pageResult.setRows(null);
        }else {
            pageResult.setTotal(page.getTotal());
            pageResult.setRows(page.getRecords());
        }
        Result<PageResult<List<Nurselevel>> > result = new Result<>();
        result.setCode(2000);
        result.setMessage("查询成功");
        result.setData(pageResult);
        return result;
    }
}




